package com.ifast.oupei.controller;


import java.util.Arrays;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.baomidou.mybatisplus.plugins.Page;
import com.ifast.common.base.BaseController;
import com.ifast.oupei.domain.LeagueDO;
import com.ifast.oupei.service.LeagueService;
import com.ifast.common.utils.Result;

/**
 * 
 * <pre>
 * 联赛信息表
 * </pre>
 * <small> 2018-04-19 10:02:56 | Aron</small>
 */
@Controller
@RequestMapping("/oupei/league")
public class LeagueController extends BaseController {
	@Autowired
	private LeagueService leagueService;
	
	@GetMapping()
	@RequiresPermissions("oupei:league:league")
	String League(){
	    return "oupei/league/league";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("oupei:league:league")
	public Result<Page<LeagueDO>> list(LeagueDO leagueDTO){
        //Wrapper<LeagueDO> wrapper = new EntityWrapper<LeagueDO>(leagueDTO);
        Page<LeagueDO> page = leagueService.ListAllLeagueInfo(getPage(LeagueDO.class));
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("oupei:league:add")
	String add(){
	    return "oupei/league/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("oupei:league:edit")
	String edit(@PathVariable("id") Integer id,Model model){
		LeagueDO league = leagueService.selectById(id);
		model.addAttribute("league", league);
	    return "oupei/league/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("oupei:league:add")
	public Result<String> save( LeagueDO league){
		leagueService.insert(league);
        return Result.ok();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("oupei:league:edit")
	public Result<String>  update( LeagueDO league){
		leagueService.updateById(league);
		return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("oupei:league:remove")
	public Result<String>  remove( Integer id){
		leagueService.deleteById(id);
        return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("oupei:league:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Integer[] ids){
		leagueService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
